package com.sgl.retrofitdemo.ui.business.main;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sgl.retrofitdemo.R;
import com.sgl.retrofitdemo.net.entity.request.UserInfo;
import com.sgl.retrofitdemo.net.entity.respons.UserInfoEntity;

public class MainActivity extends AppCompatActivity implements MainContract.MainView, View.OnClickListener {
    private MainContract.Presenter mPresenter;
    private Button mButtonPost;
    private Button mButtonGet;
    private TextView mResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mButtonPost = (Button) findViewById(R.id.button_1);
        mButtonGet = (Button) findViewById(R.id.button_2);
        mResult = (TextView) findViewById(R.id.text_1);
        mButtonPost.setOnClickListener(this);
        mButtonGet.setOnClickListener(this);
        mPresenter = new MainPresenter(this);
    }

    @Override
    public void setData(UserInfoEntity userInfoEntity) {
        String s = mResult.getText().toString() + "\n"
                + userInfoEntity.getHeadpic() + "\n"
                + userInfoEntity.getNickname() + "\n"
                + userInfoEntity.getUid();
        mResult.setText(s);
    }

    @Override
    public void setResult(String result) {
        String s = mResult.getText().toString() + "\n" + result;
        mResult.setText(s);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button_1:
                mResult.setText("");
                UserInfo userInfo = new UserInfo();
                userInfo.setAccount("11111111111111");
                userInfo.setPassword("22222222222222");
                mPresenter.testPost(userInfo);
                break;
            case R.id.button_2:
                mResult.setText("");
                mPresenter.testGet("aaaaaaa","bbbbbbb");
                break;
        }
    }
}
